package com.cy.pj.goods.dao;

import com.cy.pj.goods.pojo.Goods;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class GoodsDaoImpl implements GoodsDao{

    @Autowired
    private SqlSession sqlSession;

    @Override
    public List<Goods> findGoods() {//在此方法内部使用sqlsession实现与数据库回话
        System.out.println("findGoods()");
        String statement="com.cy.pj.goods.dao.GoodsDao.findGoods";
        return sqlSession.selectList(statement);
    }

    @Override
    public int deleteById(Integer id) {
        return 0;
    }

    @Override
    public int deleteObject(Integer... ids) {
        String statement="com.cy.pj.goods.dao.GoodsDao.deleteObject";
        Map<Object, Object> map = new HashMap<>();
        map.put("ids", ids);//value为数组
        //一般有多个参数或者是可变参数时,这个参数要封装到map,然后在进行传递
        //map中的key一般为映射文件中sql需要的参数
        return sqlSession.delete(statement,map);
    }
}
